<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="社情民意"></uni-navbar></view>

		<view class="u-line"></view>
		<u-row class="link-box" gutter="0" align="top">
			<u-col span="3" v-if="$sysMenus('sqmy_add')">
				<navigator hover-class="none" class="link-item" url="/pagesB/will/add">
					<image src="/static/img/icon_06.png" mode="aspectFill"></image>
					提交信息
				</navigator>
			</u-col>
			<u-col span="3">
				<navigator hover-class="none" class="link-item" url="/pagesB/will/list">
					<image src="/static/img/icon_08.png" mode="aspectFill"></image>
					社情民意
				</navigator>
			</u-col>
			<u-col span="3" v-if="$sysMenus('sqmy_draft')">
				<navigator hover-class="none" class="link-item" url="/pagesB/will/spare_list?status=0">
					<image src="/static/img/icon_09.png" mode="aspectFill"></image>
					草稿箱
				</navigator>
			</u-col>
			<u-col span="3" v-if="$sysMenus('sqmy_xslt')">
				<navigator hover-class="none" class="link-item" url="/pagesA/forum/list">
					<image src="/static/img/icon_13.png" mode="aspectFill"></image>
					线索论坛
				</navigator>
			</u-col>
			<u-col span="3" v-if="$sysMenus('joint')">
				<navigator hover-class="none" class="link-item" url="/pagesB/will/joint_list">
					<image src="/static/img/icon_78.png" mode="aspectFill"></image>
					我的联名
				</navigator>
			</u-col>
			<u-col span="3" v-if="$sysMenus('comprehensive_statistics')">
				<navigator hover-class="none" class="link-item" url="/pagesB/will/statistics">
					<image src="/static/img/icon_89.png" mode="aspectFill"></image>
					统计分析
				</navigator>
			</u-col>
		</u-row>

		<!-- <view class="pro-inner">
			<view class="h2-inner"><view class="h2-title">总体概况</view></view>
			<view>所有社情民意</view>
			<view class="pro-item"><u-line-progress :active-color="['#3DBBFF', '#3396FB']" :percent="100" :text="numAll"></u-line-progress></view>
			<view>已处理社情民意</view>
			<view class="pro-item"><u-line-progress :active-color="['#67FFDB', '#77DDC5']" :percent="parseInt((num2 / numAll) * 100)" :text="num2"></u-line-progress></view>
			<view>未处理社情民意</view>
			<view class="pro-item"><u-line-progress :active-color="['#FAD961', '#F76B1C']" :percent="parseInt((num5 / numAll) * 100)" :text="num5"></u-line-progress></view>
		</view> -->

		<view class="plus-inner">
			<view class="h2-inner">
				<view class="h2-title">总体概况</view>
				<view>截止{{ new Date() | parseTime('{y}.{m}.{d} {h}:{i}') }}</view>
			</view>
			<view class="plus-box">
				<view class="plus-item bg92" @click="listTo('/pagesB/will/list')">
					<view class="title">{{ numAll }}</view>
					<view>所有社情民意</view>
				</view>
				<view class="plus-item bg93" @click="listTo('/pagesB/will/list?status=1')">
					<view class="title">{{ num2 }}</view>
					<view>已处理社情民意</view>
				</view>
				<view class="plus-item bg94" @click="listTo('/pagesB/will/list?status=2')">
					<view class="title">{{ num5 }}</view>
					<view>未处理社情民意</view>
				</view>
			</view>
		</view>

		<view class="pro-row-plus">
			<view class="pro-col" @click="listTo('/pagesB/will/list?status=1')">
				<text class="text" style="color: #3396fb">{{ num2 }}</text>
				已处理
			</view>
			<view class="pro-col" @click="listTo('/pagesB/will/list?status=2')">
				<text class="text" style="color: #00b854">{{ num5 }}</text>
				未处理
			</view>
		</view>

		<view class="list-box">
			<view class="filter-inner">
				<view class="filter-btn" :class="filterType == 0 ? 'active' : ''">
					<image src="/static/img/icon_11.png" mode="widthFix"></image>
					<image src="/static/img/icon_11_f.png" mode="widthFix"></image>
					我的社情民意
				</view>
			</view>

			<view class="list-info_02" v-for="(item, index) of willList" :key="item.id" @click="navTo(item)">
				<view class="left">
					<view class="info-title">{{ item.title }}</view>
					<view class="info-btm">{{ item.createTime | parseTime('{y}-{m}-{d}') }}</view>
				</view>
				<view class="right" :class="[index % 2 == 0 ? 'bg1' : 'bg2']">社情民意</view>
			</view>
			<u-loadmore :status="loading" />
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			numAll: 0,
			num2: 0,
			num5: 0,
			filterType: 0,
			keyword: '',
			willList: [],

			sqmy: {
				clientCode: '',
				reflectUnit: '',
				reflectUser: '',
				isPublic: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadAll();
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadAll();
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.sqmy.clientCode = this.userInfo.sysUser.clientCode;
				this.sqmy.reflectUser = this.userInfo.sysUser.id;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				sqmy: this.sqmy
			};
			let url = '/sheqingminyi/sqmy/list';
			if (this.filterType == 0) {
				if (this.$sysMenus('sylb')) {
					data.userId = this.userInfo.sysUser.id;
					this.sqmy.reflectUnit = this.userInfo.sysUser.remark1;
					this.sqmy.reflectUser = '';
				} else {
					url = '/sheqingminyi/sqmy/myselflist';
					this.sqmy.reflectUnit = '';
					if (this.$roleCodes('fydw')) {
						this.sqmy.reflectUnit = this.userInfo.sysUser.remark1;
						this.sqmy.reflectUser = '';
					}
				}
				this.sqmy.isPublic = '';
			} else {
				this.sqmy.isPublic = '1';
			}
			this.$request(url, data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.willList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.willList = this.willList.concat(res.data.records);
				this.loaded = true;
				if (this.willList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		loadAll() {
			let data = {
				pageNum: 1,
				pageSize: 99999,
				sqmy: this.sqmy
			};
			let url = '/sheqingminyi/sqmy/list';
			this.sqmy.isPublic = '';
			if (this.$sysMenus('sylb')) {
				data.userId = this.userInfo.sysUser.id;
				this.sqmy.reflectUnit = this.userInfo.sysUser.remark1;
				this.sqmy.reflectUser = '';
			} else {
				url = '/sheqingminyi/sqmy/myselflist';
				this.sqmy.reflectUnit = '';
				if (this.$roleCodes('fydw')) {
					this.sqmy.reflectUnit = this.userInfo.sysUser.remark1;
					this.sqmy.reflectUser = '';
				}
			}
			this.$request(url, data).then((res) => {
				let total = res.data.total;
				let result = res.data.records;
				this.numAll = total;
				this.num2 = 0;
				this.num5 = 0;
				result.forEach((item) => {
					if (item.adoption == '未处理' || item.adoption == '联名待确认') {
						this.num5++;
					} else {
						this.num2++;
					}
				});
			});
		},
		search(e) {
			this.keyword = e;
			this.loadData('refresh');
		},
		type(e) {
			this.filterType = e;
			this.loadData('refresh');
		},
		listTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		navTo(item) {
			if (!this.userInfo) {
				this.$logout();
			} else {
				uni.navigateTo({
					url: '/pagesB/will/detail?id=' + item.id
				});
			}
		}
	}
};
</script>

<style lang="scss">
.list-box {
	// margin-bottom: 30rpx;
	padding: 30rpx 30rpx 0;
	background-color: #fff;
}

.list-info_02 .right {
	width: 236rpx;
	height: 148rpx;
	font-size: 17px;
	color: #fff;
	line-height: 148rpx;
	text-align: center;
	background: #e5231a no-repeat center;
	background-size: 100%;
	text-shadow: rgba(0, 0, 0, 0.4) 0em 0.12em 0.2em;
	letter-spacing: 2px;
}

.plus-box {
	.plus-item {
		padding-left: 116rpx;
		text-align: left;
	}
}
</style>
